<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ page import="cn.hutool.core.codec.Base64" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="org.apache.commons.codec.digest.DigestUtils" %>
<%@ page import="weaver.general.BaseBean" %>
<%@ page import="weaver.hrm.HrmUserVarify" %>
<%@ page import="weaver.hrm.User" %>
<%
    /**
     * 秘钥组成： 自定义用户名+“.”+当前时间戳(到秒)+“.”+(当前时间戳（到秒）+自定义密码)的MD5码
     * 如： admin.1503930878.e67656eb651abfa4c3cfd2a8cbbe9cf1
     */
    BaseBean baseBean = new BaseBean();
    JSONObject jsonData = new JSONObject();
    User user = HrmUserVarify.getUser(request, response);
    String loginid = user.getLoginid();
    String baseUrl = "http://192.168.0.22/singleLogin";
    baseBean.writeLog(">>>>>mesSSO.jsp>>>>loginid=" + loginid);
    String keys = "MES-BFDZ";
    String timestamp = getTimestamp();
    String encryContent = loginid + timestamp +keys;
    String sign = generateMD5(encryContent);
    baseBean.writeLog(">>>>>mesSSO.jsp>>>>encryContent=" + encryContent+",sign="+sign);
    JSONObject jsonParam = new JSONObject();
    jsonParam.put("user",loginid);
    jsonParam.put("time",timestamp);
    jsonParam.put("sign",sign);
    String encodepParam = Base64.encode(jsonParam.toJSONString());
    jsonData.put("result", baseUrl+"?params="+encodepParam);
    out.print(jsonData.toJSONString());
%>
<%!
    /**
     * 获取当前时间戳
     * @return
     */
    private String getTimestamp() {
        // 获取当前时间的毫秒时间戳
        long currentTimeMillis = System.currentTimeMillis();
        // 输出10位时间戳
        return String.format("%010d", currentTimeMillis);
    }


    // 使用Apache Commons Codec直接生成MD5哈希
    private String generateMD5(String input) {
        return DigestUtils.md5Hex(input).toUpperCase();
    }
%>